<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 适合打劫银行的日子 -->
    <script>
      var goodDaysToRobBank = function (s, time) {
        let n = s.length
        let up = new Array(n).fill(0)
        let down = new Array(n).fill(0)
        for (let i = 1; i < n; i++) {
          // 更新down
          if (s[i] <= s[i - 1]) {
            down[i] = down[i - 1] + 1
          }
        }
        for (let i = n - 2; i >= 0; i--) {
          if (s[i] <= s[i + 1]) {
            up[i] = up[i + 1] + 1
          }
        }
        let res = []
        for (let i = time; i < n - time; i++) {
          if (up[i] >= time && down[i] >= time) res.push(i)
        }
        return res
      }
      console.log(goodDaysToRobBank([5, 3, 3, 3, 5, 6, 2], 2))
    </script>
  </body>
</html>
